using System.Windows;
using System.Windows.Media;

namespace YouVisio.Silverlight.TextDiff.Extensions
{
    public static class FrameworkElement_Ext
    {
        public static FrameworkElement FindChildByName(this FrameworkElement obj, string name)
        {
            var count = VisualTreeHelper.GetChildrenCount(obj);
            for(var i = 0; i < count; i++)
            {
                var current = VisualTreeHelper.GetChild(obj, i) as FrameworkElement;
                if(current == null) continue;
                if(current.Name == name)
                {
                    return current;
                }
                else
                {
                    var child = FindChildByName(current, name);
                    if (child != null) return child;
                }
            }
            return null;
        }
    }
}